// 已经发起请求的队列 Array<{url: string, timestamp:number}>
const requestedQueueArray = [];
// 列队的最大长度 number
const MAX_SIZE = 5;
// 防抖时长(ms) number
const DEBOUNCE_TIME = 2000;
/**
 * @description 判断请求在指定时间内，是否过于频繁
 * @param {String} url  请求地址
 * @return {Boolean} 在指定时间内，请求是否重复出现
 * */
export const isNeedDebounce = (url) => {
	
	let result = false;
	
	requestedQueueArray.forEach((v)=>{
		if(v.url === url && +new Date() - v.timestamp < DEBOUNCE_TIME){
			result = true;
		}
	});
	if(result){
		return result;
	}
	
	const timestamp = +new Date();
	
	if(requestedQueueArray.length > MAX_SIZE - 1){
		requestedQueueArray.shift();
	}
	
	requestedQueueArray.push({url, timestamp});
	
	return result;
}
